package com.hsp_java.set_;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Set;

@SuppressWarnings({"all"})
public class LinkedHashSetSource {

    public static void main(String[] args) {
        Set set = new LinkedHashSet();
        set.add(new String("AA"));
        set.add(456);
        set.add(456);
        set.add(new Customer("刘", 1001));
        set.add(123);
        set.add("HSP");

        System.out.println("set = "  + set);

        //1. 加入顺序和取出顺序一致
        //2. LinkedHashSet 底层维护的是LinkedHashMap
        //3. LinkedHashSet 底层结构(数组table+双向链表)
        //4. 第一次初始化是 将数组扩容到 16 , 存放的结点类型是LinkedHashMap$Entry
        //5. 数组是HashMap$Node[] 存放的元素/数据是 LinkedHashMap$Entry
        /*
            //继承关系在内部类完成
            static class Entry<K,V> extends HashMap.Node<K,V> {
                LinkedHashMap.Entry<K,V> before, after;
                Entry(int hash, K key, V value, HashMap.Node<K,V> next) {
                    super(hash, key, value, next);
                }
            }
         */


    }
}

class Customer {
    private String name;
    private int no;

    public Customer(String name, int no) {
        this.name = name;
        this.no = no;
    }
}